package kr.hkit.powerjava.chapter24.service;

import java.util.Comparator;
import java.util.Scanner;

import kr.hkit.powerjava.chapter24.dao.InterfaceDAO;
import kr.hkit.powerjava.chapter24.vo.Student;

public class ServiceStudent extends ServiceItem<Student>{
	
	public ServiceStudent(InterfaceDAO<Student> dao, Scanner sc) {
		super(dao, sc);
	}

	@Override
	public Student inputItemInfo(boolean gubun) {
		System.out.print("학번 이름");
		int num = sc.nextInt();
		String name = sc.next();
		if(gubun) {
			System.out.print("국어 영어 수학");
			int kor = sc.nextInt();
			int eng = sc.nextInt();
			int math = sc.nextInt();
			return new Student(num, name, kor, eng, math);
		} else {
			return new Student(num, name);
		}
	}

	@Override
	public void prnSubMenu() {
		System.out.print("1.이름순 정렬\t2.성적순 정렬\t3.번호순 정렬");
		int subnum = sc.nextInt();
		switch(subnum) {
			case 1:
				dao.prnListItem(new Comparator<Student>() {
					@Override
					public int compare(Student o1, Student o2) {
						return o1.getStdName().hashCode() - o2.getStdName().hashCode();
					}
				});
				break;
			case 2:
				dao.prnListItem(new Comparator<Student>() {
					@Override
					public int compare(Student o1, Student o2) {
						return o1.totalScore() - o2.totalScore();
					}
				});
				break;
			case 3:
				dao.prnListItem(null);
				break;
			default:
				break;
		}	
	}
}